﻿using System;
using AppCommon;
using Controller;

public partial class Modules_TourTrongNuocControl : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindData();
        }
    }

    public void BindData()
    {        
        var idTtn = GetIdTourtrongnuoc();
        var controller = new VYC01Controller();
        var model = controller.GetTheoLoaiTour(idTtn, 1);

        if (model.Count > 0)
        {
            imgFirstTour.ImageUrl = Constants.UPLOAD_TOUR + model[0].AnhDaiDien;
            linkFirstTour.NavigateUrl = "~/tour/" + model[0].UniqueId;
            litTitleFirstTour.Text = model[0].TieuDe;
            litNgaydi.Text = model[0].NgayDi.ToString("dd/MM/yyyy");
            litTime.Text = (model[0].NgayDen - model[0].NgayDi).TotalDays.ToString();
            litGia.Text = String.Format("{0:###,###,##0}", model[0].Gia) + " VNĐ";

            repeaterTourtn.DataSource = model;
            repeaterTourtn.DataBind();
        }
    }

    public int GetIdTourtrongnuoc()
    {
        var uniqueId = AppCommon.Common.ConvertToUnSign(Constants.TITLE_TOUR_TRONGNUOC);
        var controller = new VYC02Controller();
        var model = controller.GetByUniqueId(uniqueId);
        if (model.Count > 0)
        {
            linkTourtrongnuoc.NavigateUrl = "~/category/" + model[0].UniqueId + "/";
            return model[0].Id;
        }
        return 0;
    }
}